package com.lzb.play.dialog;

import android.content.Context;
import android.media.AudioManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.SeekBar;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.VolumeUtils;
import com.lzb.play.Content;
import com.lzb.play.R;
import com.lzb.play.basic.dialog.BaseSmartDialog;
import com.lzb.play.databinding.DialogRecordSaveBinding;
import com.lzb.play.databinding.DialogVolumeSetBinding;

public class RecordSaveDialog extends BaseSmartDialog<DialogRecordSaveBinding> implements View.OnClickListener {

    private String audioPath;

    public RecordSaveDialog(@NonNull Context context) {
        super(context);
    }

    public void setAudioPath(String audioPath) {
        this.audioPath = audioPath;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_record_save;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivCancel.setOnClickListener(this);
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        mDataBinding.etName.setText(FileUtils.getFileNameNoExtension(audioPath));
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ivCancel) {
            dismiss();
        } else if (id == R.id.tvCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            String name = mDataBinding.etName.getText().toString().trim();
            if (TextUtils.isEmpty(name)) {
                ToastUtils.showShort(getContext().getString(R.string.please_input_name));
                return;
            }
            String path = PathUtils.getFilesPathExternalFirst() + Content.myRecord + "/" + name + ".mp3";
            FileUtils.copy(audioPath, path);
            ToastUtils.showShort(getContext().getString(R.string.save_suc));
            dismiss();
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm();
    }
}
